import peopleApi from '@/api/people'
const state = {
  list: [],
  pages: { page: 1, limit: 5, count: 0 },
}

const mutations = {
  GET_INFO: (state, payload) => {
    state.pages = Object.assign({}, state.pages, { count: payload.count })
    state.list = payload.rows
  },
  CHANGE_PAGE: (state, payload) => {
    state.pages = payload
  }
}
const actions = {
  async getInfo({ commit, state }, obj) {
    if (obj) {
      commit('CHANGE_PAGE', obj)
    }
    const data = await peopleApi.getInfo(state.pages)
    console.log(data);
    commit('GET_INFO', data)
  },
  async change({ dispatch }, data) {
    const res = await peopleApi.update(data)
    await dispatch('getInfo')
    return res
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
